package com.web.service.impl;

import com.web.aspect.MyLog;
import com.web.dao.StudentDAO;
import com.web.dao.impl.StudentDAOImpl;
import com.web.entity.PageVO;
import com.web.entity.Student;
import com.web.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Resource
    private StudentDAO studentDAO;

    @Override
    public List<Student> findAllStudents() {
        return studentDAO.selectAllStudents();
    }

    @MyLog("这是分页方法")
    @Override
    public PageVO findStudentPage(int current, int pageSize) {
        //int x = 10 / 0;
        //查询学生的总数
        int count = studentDAO.selectStudentsCount();
        //分页查询学生  current 页 --> start 行
        int start = (current - 1) * pageSize;
        List<Student> students = studentDAO.selectStudentsPage(start,pageSize);
        PageVO pageVO = new PageVO(current,pageSize,count,students);
        return pageVO;
    }

    @Override
    public Student findStudentById(int id) {
        return studentDAO.selectStudentById(id);
    }

    @Override
    public void addStudent(Student student) {
        studentDAO.insertStudent(student);
    }

    @Override
    public void updateStudentById(Student student) {
        studentDAO.updateStudentById(student);
    }

    @Override
    public void removeStudentById(int id) {
        studentDAO.deleteStudentById(id);
    }
}
